<?php
/**
 * Author:Arthur
 * Date:2013-5-6
 * File Name:getUpdateStatus.php
 * Email:kingarthurx@sina.cn
 */
  require_once (dirname(__FILE__)."/../config/config.php");
  		
  
  if(isset($_GET['method'])){
  	 if(isset($_GET['mac'])){
	  	$sql1="select * from zy_equipment where MacAddress='".$_GET['mac']."'";
	  	$rss = mysql_query($sql1);
	  	$rows = mysql_fetch_array($rss);
	  }
  	 $unm = updateStatus($rows['updater']);
  	 if($unm == 1){
  	 	$error_message = "<result>success</result>\n";
  	 	outPutXml($error_message);
  	 }else{
  	 	$error_message = "<result>error</result>\n";
  	 	outPutXml($error_message);
  	 }
  }else{
  	$content = getUpdateStatus();
  	outPutXml($content);
  }
  
  /**
   * 当API取出这条记录时,把routeupdate 更新为 1:未有更新记录
   */
  function updateStatus($user_id){
  		$sql="UPDATE zy_updatestatus set routeupdate=1 where user_id ='".$user_id."'";
  		$rs = mysql_query($sql);
  		if($rs > 0){
  			return 1;
  		}else{
  			return 0;
  		}
  		
  } 
 
  function getUpdateStatus(){
  	$content = "";
  		if(isset($_GET['mac'])){
	  	$sql1="select * from zy_equipment where MacAddress='".$_GET['mac']."'";
	  	$rss = mysql_query($sql1);
	  	$rows = mysql_fetch_array($rss);
 
  		$sql="select * from zy_updatestatus where user_id='".$rows['updater']."'";
  		$rs = mysql_query($sql);
  		$row = mysql_fetch_array($rs);
  		
  		$content.= "<result>\n";
		$content.= "<routeupdate>".$row['routeupdate']."</routeupdate>\n";
		$content.= "</result>\n";
	}
  	return $content;
  } 
  
  function outPutXml($content) {
	header("Content-type:text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
	echo "<netcuberesult>\n";
	echo $content;
	echo "</netcuberesult>";
	die();
}
